package com.uenpay.im.weight;

import android.app.Dialog;
import android.content.Context;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;

import com.uenpay.im.R;
import com.uenpay.im.callback.IOnBottomDialogListener;
import com.uenpay.im.callback.OnBottomDialogListener;


/**
 * dialog
 * 
 * @author Sl
 * @date 2014/8/9
 * @copyRight http://www.qiyunxin.com
 */
public class BottomDialog {

	public static void showBottomDialog(Context mContext, String top_str,
			String center_str, String bottom_str, final int top_color,
			final IOnBottomDialogListener top_listener,
			final IOnBottomDialogListener center_listener) {
		final Dialog dialog = new Dialog(mContext, R.style.pop_dialog);
		dialog.setContentView(R.layout.pop_dialog_more);
		Window win = dialog.getWindow();
		win.setGravity(Gravity.BOTTOM);
		win.setWindowAnimations(R.style.dialogWindowAnim);
		dialog.setCanceledOnTouchOutside(true);
		dialog.show();
		win.setLayout(android.view.ViewGroup.LayoutParams.MATCH_PARENT,
				android.view.ViewGroup.LayoutParams.WRAP_CONTENT);

		Button topBtn = (Button) dialog.findViewById(R.id.top_btn);

		if (!TextUtils.isEmpty(top_str)) {
			topBtn.setText(top_str);
		}
		if (top_color != -1)
			topBtn.setTextColor(top_color);

		Button centerBtn = (Button) dialog.findViewById(R.id.center_btn);

		if (!TextUtils.isEmpty(center_str)) {
			centerBtn.setText(center_str);
			centerBtn.setVisibility(View.VISIBLE);
		}

		Button bottomBtn = (Button) dialog.findViewById(R.id.bottom_btn);

		if (!TextUtils.isEmpty(bottom_str))
			bottomBtn.setText(bottom_str);

		if (center_listener != null) {
			centerBtn.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					dialog.dismiss();
					center_listener.onClicked();
				}
			});
		}
		if (top_listener != null) {
			topBtn.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					dialog.dismiss();
					top_listener.onClicked();
				}
			});
		}
		bottomBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				dialog.dismiss();
			}
		});
	}

	public static void showBottomRedDialog(Context mContext,
			final OnBottomDialogListener top_listener,
			final OnBottomDialogListener center_listener) {
		final Dialog dialog = new Dialog(mContext, R.style.pop_dialog);
		dialog.setContentView(R.layout.pop_dialog_red);
		Window win = dialog.getWindow();
		win.setGravity(Gravity.BOTTOM);
		win.setWindowAnimations(R.style.dialogWindowAnim);
		dialog.setCanceledOnTouchOutside(true);
		dialog.show();
		win.setLayout(android.view.ViewGroup.LayoutParams.MATCH_PARENT,
				android.view.ViewGroup.LayoutParams.WRAP_CONTENT);

		Button topBtn = (Button) dialog.findViewById(R.id.top_btn);
		Button centerBtn = (Button) dialog.findViewById(R.id.center_btn);
		Button bottomBtn = (Button) dialog.findViewById(R.id.bottom_btn);

		if (center_listener != null) {
			centerBtn.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					dialog.dismiss();
					center_listener.onClicked();
				}
			});
		}
		if (top_listener != null) {
			topBtn.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					dialog.dismiss();
					top_listener.onClicked();
				}
			});
		}
		bottomBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				dialog.dismiss();
			}
		});
	}

	public static void showBottomDynamicDialog(Context mContext,
											   final OnBottomDialogListener top_listener,
											   final OnBottomDialogListener center_listener) {
		final Dialog dialog = new Dialog(mContext, R.style.pop_dialog);
		dialog.setContentView(R.layout.pop_dialog_dynamic);
		Window win = dialog.getWindow();
		win.setGravity(Gravity.BOTTOM);
		win.setWindowAnimations(R.style.dialogWindowAnim);
		dialog.setCanceledOnTouchOutside(true);
		dialog.show();
		win.setLayout(android.view.ViewGroup.LayoutParams.MATCH_PARENT,
				android.view.ViewGroup.LayoutParams.WRAP_CONTENT);

		Button topLayout = (Button) dialog
				.findViewById(R.id.pop_dialog_more_one_btn1);

		Button centerLayout = (Button) dialog
				.findViewById(R.id.pop_dialog_more_one_btn2);

		Button bottomLayout = (Button) dialog
				.findViewById(R.id.btn_cancel);

		if (center_listener != null) {
			centerLayout.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					dialog.dismiss();
					center_listener.onClicked();
				}
			});
		}
		if (top_listener != null) {
			topLayout.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					dialog.dismiss();
					top_listener.onClicked();
				}
			});
		}
		bottomLayout.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				dialog.dismiss();
			}
		});
	}
}
